package com.ushine.web.component.design.chain.demo.factory;

import com.ushine.web.component.design.chain.config.ApplicationContextHelper;
import com.ushine.web.component.design.chain.config.ChainBaseParams;
import com.ushine.web.component.design.chain.handler.AbstractChainTemplateHandler;
import com.ushine.web.component.design.chain.demo.*;
import com.ushine.web.component.design.chain.factory.AbstractChainTemplateFactory;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author: yls
 * @Date: 2021/12/24 13:24
 * @Description: 请求责任链：静态工厂
 * @Version 1.0
 */
@Component
public class RequestChainTemplateFactory extends AbstractChainTemplateFactory {

    @Resource
    public ApplicationContextHelper applicationContextHelper;

    /**
     * 功能描述:
     * 〈 采用工厂模式创建过滤链 〉
     *
     * @return : java.util.List<com.yls.ylsgatewaystandalone.chain.GatewayHandler>
     * @author : yls
     * @date : 2021/12/24 13:44
     */
    public List<AbstractChainTemplateHandler<ChainBaseParams>> initBaseChainTemplateHandler() {
        List<AbstractChainTemplateHandler<ChainBaseParams>> abstractChainTemplateHandlers = new ArrayList<>();
        /*
         * 基础过滤链：请求头 =》用户 =》服务状态 =》签名 =》扣费
         */
        creteGatewayHandle(applicationContextHelper, InitRequestHandler.class, 0, abstractChainTemplateHandlers);
        creteGatewayHandle(applicationContextHelper, HeaderHandler.class, 1, abstractChainTemplateHandlers);
        creteGatewayHandle(applicationContextHelper, UserStatusHandler.class, 2, abstractChainTemplateHandlers);
        creteGatewayHandle(applicationContextHelper, ProductHandler.class, 3, abstractChainTemplateHandlers);
        creteGatewayHandle(applicationContextHelper, SignatureHandler.class, 4, abstractChainTemplateHandlers);
        creteGatewayHandle(applicationContextHelper, DeductionHandler.class, 6, abstractChainTemplateHandlers);
        /*
         * 初始化过滤链
         */
        initGatewayHandles(abstractChainTemplateHandlers);
        return abstractChainTemplateHandlers;
    }


}
